import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
// 导入组织架构路由模块
import departmentRouter from './modules/department'
// 导入审批路由模块
import approvalRouter from './modules/approval'
// 导入考勤路由模块
import attendanceRouter from './modules/attendance'
// 导入员工路由模块
import employeeRouter from './modules/employee'
// 导入权限路由模块
import permissionRouter from './modules/permission'
// 导入角色路由模块
import roleRouter from './modules/role'
// 导入薪资路由模块
import salaryRouter from './modules/salary' 
// 导入社保路由模块
import socialRouter from './modules/social'


// 静态路由配置
export const constantRoutes = [
  // 静态路由-所有人都能访问的页面
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  
  
]

// 动态路由配置
export const asyncRoutes=[
  // 动态路由-有权限的人才能访问对应页面
  departmentRouter,
  roleRouter,
  employeeRouter,
  permissionRouter,
  attendanceRouter,
  approvalRouter,
  salaryRouter,
  socialRouter,

]

const createRouter = () => new Router({
  mode: 'history', // 路由模式
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes//默认引入静态路由
})

// 当前路由实例总数据
const router = createRouter()

// 重置路由--用于退出登录后重置相关用户的权限路由
export function resetRouter() {
  // 创建新的路由实例，只包含静态路由数据
  const newRouter = createRouter()
  // console.log(newRouter);
  // 将新的路由实例赋值给当前路由实例数据，这样就相当于重置路由了
  router.matcher = newRouter.matcher // 重置路由
  // console.log(router.matcher);
  
}

export default router
